﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Helpers;
using System.Web.Mvc;
using Thaire.Investment.Common;
using ThaireInvestmentWeb.Models;

namespace ThaireInvestmentWeb.Util
{





    public class WebUtil
    {
        public static String DisplayXIfNullOrZero(String value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return "X";

            }
            else if (value == "0")
            {
                return "X";
            }else{
                return value;
            }
        }

        public static String GetReportExcelName(string basename, bool initial)
        {
            string ini = "";
            if(initial)
              ini =  "Initial";
            return ConfigurationManager.AppSettings[basename + ini];
        }

        public static String GetMaturityStatus(DateTime? maturityDate)
        {
            if (maturityDate.GetValueOrDefault().Date >= DateTime.Now.Date)
            {
                return "Matured";
            }
            else
                return "Alive";
        }

        public static String NonApplicableIfZero(dynamic val)
        {
            if (val == null)
                return string.Empty;

            decimal value = (decimal)val;

            if (value < 0)
                return "N/A";
            else
                return value.ToString("0.00");



        }


        public static DateTime SystemDate
        {
            get { return DateTime.Now; }
        }
        public static String FormatDate(DateTime? date)
        {
            if (date.HasValue)
                return date.Value.ToString("dd/MM/yyyy");

            return null;
        }

        public static String FormatDate(dynamic date)
        {
            if (date == null)
                return string.Empty;
            DateTime dVal = (DateTime)date;
            return date.ToString("dd/MM/yyyy");
        }

        public static String FormatDecimal5Digit(dynamic val)
        {
            if (val == null)
                return string.Empty;
            decimal dVal = (decimal)val;
            return val.ToString("0.00000");
        }

        public static String FormatCurrency5(dynamic val)
        {
            if (val == null)
                return string.Empty;
            decimal dVal = (decimal)val;
            return val.ToString("#,##0.00000");
        }

        public static String FormatCurrency6(dynamic val)
        {
            if (val == null)
                return string.Empty;
            decimal dVal = (decimal)val;
            return val.ToString("#,##0.000000");
        }

        public static String FormatCurrency2(dynamic val)
        {
            if (val == null)
                return string.Empty;
            decimal dVal = (decimal)val;
            return val.ToString("#,##0.00");
        }
        public static String FormatCurrency0(dynamic val)
        {
            if (val == null)
                return string.Empty;
            decimal dVal = (decimal)val;
            return val.ToString("#,##0");
        }
        public static String FormatDecimal2Digit(dynamic val)
        {
            if (val == null)
                return string.Empty;
            decimal dVal = (decimal)val;
            return val.ToString("#,##0.00");
        }
        public static String FormatDecimal2DigitFree(dynamic val)
        {
            if (val == null)
                return string.Empty;
            decimal dVal = (decimal)val;
            return val.ToString("#,###.##");
        }
        public static String FormatInt(dynamic val)
        {
            if (val == null)
                return string.Empty;
            int dVal = (int)val;
            return val.ToString("#,##0");
        }


        public static SelectListItem SelectListSelectDefault()
        {
            return new SelectListItem() { Selected = true, Text = "--Select data--", Value = "" };
        }

        public static SelectListItem SelectListAllDefault()
        {
            return new SelectListItem() { Selected = true, Text = "-----ALL-----", Value = "" };
        }

        public static void ClearSelectionDropDown(IList<SelectListItem> data)
        {
            foreach (var item in data)
            {
                item.Selected = false;
            }
        }

        //public static SelectListItem GetSelectionItemDropDown(IList<SelectListItem> data)
        //{
        //    foreach (var item in data)
        //    {
        //        if (item.Selected)
        //            return item;

        //    }
        //    return null;
        //}

        public static String GetSelectionText(IList<SelectListItem> data, String value)
        {
            SelectListItem item = data.Where(x => x.Value == value).SingleOrDefault();
            if (item != null)
            {
                if (item.Value == "" || item.Value == null)
                    return null;
                else
                    return item.Text;
            }
            else
                return null;
        }

        public static WebGridColumn[] GridSelect(WebGrid grid, HtmlHelper helper, InstrumentType type)
        {
            if (type == InstrumentType.FixedIncome)
            {
                return grid.Columns(

                   grid.Column(header: "เลือก", canSort: false, format: (item) => helper.Raw("<input class=\"check-box\"  id=\"Selected\" name=\"Selected\" type=\"checkbox\" value=\"" + item.Key + "\"/>")),
                     grid.Column(header: "NO.", format: x => (x.WebGrid.Rows.IndexOf(x) + 1) + (grid.PageIndex * grid.RowsPerPage), canSort: false),

                grid.Column( header: "TTM (Yrs.)",style:"columndecimal" ,format:(item)=> (item.TimeToMaturityDate )),
                grid.Column(columnName: "TransactionType", header: "Trans.", canSort: false),
                grid.Column( header: "Trade Date", format: (item)=> @ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.TradeDate ) ),
                grid.Column( header: "Settle. Date", format: (item)=> @ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.SettlementDate ) ),
                grid.Column( header: "Unit",style:"columnNumber", format: (item)=> @ThaireInvestmentWeb.Util.WebUtil.FormatCurrency0(item.TransactionUnit ) ),
                grid.Column( header: "Remain Unit",style:"columnNumber" ,format: (item)=> @ThaireInvestmentWeb.Util.WebUtil.FormatCurrency0(item.RemainUnit ) ),
                grid.Column( header: "Par", style:"columnNumber",format: (item)=> @ThaireInvestmentWeb.Util.WebUtil.FormatCurrency5(item.Par ) ),
                grid.Column(header: "Cost Yield", style: "columnNumber", format: (item) => @ThaireInvestmentWeb.Util.WebUtil.FormatCurrency5(item.CostYield_YTM)),
                grid.Column(header: "Purchase (THB)", style: "columnNumber", format: (item) => @ThaireInvestmentWeb.Util.WebUtil.FormatCurrency5(item.PurchaseValue_LocalTHB))

                     //grid.Column(columnName: "TransactionType", header: "TransactionType", canSort: false),
                     //grid.Column(header: "ประเภท SBL/REPO", format: (item) => "ยกเลิก"),
                     //grid.Column(columnName: "CounterParty", header: "Counter party", canSort: false),
                     //grid.Column(columnName: "TimeToMaturityDate", header: "Time to Maturity", style: "columndecimal"),
                     //grid.Column(header: "Transaction", format: (item) => "ยกเลิก"),
                     //grid.Column(header: "Trade Date", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.TradeDate)),
                     //grid.Column(header: "Settlement Date", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.SettlementDate)),
                     //grid.Column(header: "Transaction Unit", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatInt(item.TransactionUnit)),
                     //grid.Column(header: "Remain Unit", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatInt(item.RemainUnit)),

                     //grid.Column(header: "Par", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.Par)),
                     //grid.Column(header: "Cost Yield (YTM)", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.CostYield_YTM)),
                     //grid.Column(header: "Coupon Payment Date", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.CouponPaymentDate)),
                     //grid.Column(header: "Coupon", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.Coupon)),
                     //grid.Column(header: "Purchase Value (Local THB)", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.PurchaseValue_LocalTHB))
                     
                     );

            }

            if (type == InstrumentType.UnitTrust)
            {
                return grid.Columns(

                   grid.Column(header: "เลือก", canSort: false, format: (item) => helper.Raw("<input class=\"check-box\"  id=\"Selected\" name=\"Selected\" type=\"checkbox\" value=\"" + item.Key + "\"/>")),
                     grid.Column(header: "NO.", format: x => (x.WebGrid.Rows.IndexOf(x) + 1) + (grid.PageIndex * grid.RowsPerPage), canSort: false),

                     grid.Column(columnName: "UnitTrustTransactionType", header: "Trans", canSort: false),

                     grid.Column(columnName: "UnitTrustCounterPartyName", header: "Counter party", canSort: false),

                     grid.Column(header: "Time to Maturity", format: (item) => ThaireInvestmentWeb.Util.WebUtil.NonApplicableIfZero(item.UnitTrustTimeToMaturity)),
                     grid.Column(header: "Trade Date", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.UnitTrustTradeDate)),
                     grid.Column(header: "Settlement Date", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.UnitTrustSettlementDate)),
                     grid.Column(header: "Transaction Unit", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatInt(item.UnitTrustUnit)),
                     grid.Column(header: "Remain Unit", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatInt(item.UnitTrustRemainUnit)),

                     grid.Column(header: "Par", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.UnitTrustPar)),
                     grid.Column(header: "Nav", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.UnitTrustNav)),
                     grid.Column(header: "Nav Date", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.UnitTrustNavDate)),

                      grid.Column(header: "BID Price / Unit", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.UnitTrustBidPrice)),
                     grid.Column(header: "BID Price Date", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.UnitTrustBidPriceDate)),

                     grid.Column(header: "Purchase (THB)", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.UnitTrustPurchaseValueNet)),
                     grid.Column(header: "BID Price Amount", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.UnitTrustBidPriceAmt))


                    );

            }

            if (type == InstrumentType.Equity)
            {
                return grid.Columns(

                   grid.Column(header: "เลือก", canSort: false, format: (item) => helper.Raw("<input class=\"check-box\"  id=\"Selected\" name=\"Selected\" type=\"checkbox\" value=\"" + item.Key + "\"/>")),
                     grid.Column(header: "NO.", format: x => (x.WebGrid.Rows.IndexOf(x) + 1) + (grid.PageIndex * grid.RowsPerPage), canSort: false),

                     grid.Column(columnName: "EquityTransactionType", header: "Trans", canSort: false),

                     grid.Column(columnName: "EquityCounterPartyName", header: "Counter party", canSort: false),

                     grid.Column(header: "Time to Maturity", format: (item) => ThaireInvestmentWeb.Util.WebUtil.NonApplicableIfZero(item.EquityTimeToMaturity)),
                     grid.Column(header: "Trade Date", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.EquityTradeDate)),
                     grid.Column(header: "Settlement Date", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.EquitySettlementDate)),
                     grid.Column(header: "Transaction Unit", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatInt(item.EquityUnit)),
                     grid.Column(header: "Remain Unit", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatInt(item.EquityRemainUnit)),

                     grid.Column(header: "Par", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.EquityPar)),
                     grid.Column(header: "Nav", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.EquityNav)),
                     grid.Column(header: "Nav Date", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.EquityNavDate)),

                      grid.Column(header: "BID Price / Unit", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.EquityBidPrice)),
                     grid.Column(header: "BID Price Date", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.EquityBidPriceDate)),

                     grid.Column(header: "Purchase (THB)", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.EquityPurchaseValueNet)),
                     grid.Column(header: "BID Price Amount", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.EquityBidPriceAmt))


                    );

            }
            if (type == InstrumentType.DepositAtFinancial)
            {
                return grid.Columns(

                   grid.Column(header: "เลือก", canSort: false, format: (item) => helper.Raw("<input class=\"check-box\"  id=\"Selected\" name=\"Selected\" type=\"checkbox\" value=\"" + item.Key + "\"/>")),
                     grid.Column(header: "NO.", format: x => (x.WebGrid.Rows.IndexOf(x) + 1) + (grid.PageIndex * grid.RowsPerPage), canSort: false),

                     grid.Column(columnName: "DepositTransactionType", header: "Trans.", canSort: false),
                     grid.Column(columnName: "DepositVoucherNo", header: "A/C No. , Voucher No.", canSort: false),
                      grid.Column(columnName: "DepositBankName", header: "Bank Name", canSort: false),
                       grid.Column(columnName: "DepositBankBranchName", header: "Branch", canSort: false),
                     grid.Column(header: "TTM.", format: (item) => ThaireInvestmentWeb.Util.WebUtil.NonApplicableIfZero(item.DepositTtm)),
                     grid.Column(header: "Settle Date", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.DepositSettlementDate)),
                       grid.Column(columnName: "DepositTerm", header: "TERM", canSort: false),
                     grid.Column(header: "AMOUNT", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.DepositAmount))
                    );

            }
            return null;

        }
        public static WebGridColumn[] GridSelected(WebGrid grid, HtmlHelper helper, UrlHelper url, InstrumentType type)
        {
            if (type == InstrumentType.FixedIncome)
            {
                return grid.Columns(
              grid.Column(header: "ลบ", canSort: false, format: (item) => helper.Raw("<input type=\"image\" id=\"BtnDelete\"  name=\"BtnDelete\"  onclick=\"return del('" + item.Key + "')\"  value=\"" + item.Key + "\" src=\"" + url.Content("~/Content/images/delete.png") + "\"  title=\"ลบ\">")),
              grid.Column(header: "NO.", format: item => (item.WebGrid.Rows.IndexOf(item) + 1) + (grid.PageIndex * grid.RowsPerPage), canSort: false),


                //grid.Column(columnName: "TransactionType", header: "TransactionType", canSort: false),
                    //grid.Column(header: "ประเภท SBL/REPO", canSort: false, format: (item) => "ยกเลิก"),
                    //grid.Column(columnName: "CounterParty", header: "Counter party", canSort: false),
                    //grid.Column(columnName: "TimeToMaturityDate", header: "Time to Maturity", style: "columndecimal"),
                    //grid.Column(header: "Transaction", canSort: false, format: (item) => "ยกเลิก"),
                    //grid.Column(header: "Trade Date", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.TradeDate)),
                    //grid.Column(header: "Settlement Date", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.SettlementDate)),
                    //grid.Column(header: "Transaction Unit", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatInt(item.TransactionUnit)),
                    //grid.Column(header: "Remain Unit", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatInt(item.RemainUnit)),

                //grid.Column(header: "Par", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.Par)),
                    //grid.Column(header: "Cost Yield (YTM)", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.CostYield_YTM)),
                    //grid.Column(header: "Coupon Payment Date", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.CouponPaymentDate)),
                    //grid.Column(header: "Coupon", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.Coupon)),
                    //grid.Column(header: "Purchase Value (Local THB)", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.PurchaseValue_LocalTHB)));


                 grid.Column(header: "TTM (Yrs.)", style: "columndecimal", format: (item) => (item.TimeToMaturityDate)),
                grid.Column(columnName: "TransactionType", header: "Trans.", canSort: false),
                grid.Column(header: "Trade Date", format: (item) => @ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.TradeDate)),
                grid.Column(header: "Settle. Date", format: (item) => @ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.SettlementDate)),
                grid.Column(header: "Unit", style: "columnNumber", format: (item) => @ThaireInvestmentWeb.Util.WebUtil.FormatCurrency0(item.TransactionUnit)),
                grid.Column(header: "Remain Unit", style: "columnNumber", format: (item) => @ThaireInvestmentWeb.Util.WebUtil.FormatCurrency0(item.RemainUnit)),
                grid.Column(header: "Par", style: "columnNumber", format: (item) => @ThaireInvestmentWeb.Util.WebUtil.FormatCurrency5(item.Par)),
                grid.Column(header: "Cost Yield", style: "columnNumber", format: (item) => @ThaireInvestmentWeb.Util.WebUtil.FormatCurrency5(item.CostYield_YTM)),
                grid.Column(header: "Purchase (THB)", style: "columnNumber", format: (item) => @ThaireInvestmentWeb.Util.WebUtil.FormatCurrency5(item.PurchaseValue_LocalTHB)));
            }

            if (type == InstrumentType.UnitTrust)
            {
                return grid.Columns(

                     grid.Column(header: "ลบ", canSort: false, format: (item) => helper.Raw("<input type=\"image\" id=\"BtnDelete\"  name=\"BtnDelete\"  onclick=\"return del('" + item.Key + "')\"  value=\"" + item.Key + "\" src=\"" + url.Content("~/Content/images/delete.png") + "\"  title=\"ลบ\">")),
                     grid.Column(header: "NO.", format: item => (item.WebGrid.Rows.IndexOf(item) + 1) + (grid.PageIndex * grid.RowsPerPage), canSort: false),


                     grid.Column(columnName: "UnitTrustTransactionType", header: "Trans", canSort: false),

                     grid.Column(columnName: "UnitTrustCounterPartyName", header: "Counter party", canSort: false),

                     grid.Column(header: "Time to Maturity", format: (item) => ThaireInvestmentWeb.Util.WebUtil.NonApplicableIfZero(item.UnitTrustTimeToMaturity)),
                     grid.Column(header: "Trade Date", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.UnitTrustTradeDate)),
                     grid.Column(header: "Settlement Date", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.UnitTrustSettlementDate)),
                     grid.Column(header: "Transaction Unit", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatInt(item.UnitTrustUnit)),
                     grid.Column(header: "Remain Unit", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatInt(item.UnitTrustRemainUnit)),

                     grid.Column(header: "Par", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.UnitTrustPar)),
                     grid.Column(header: "Nav", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.UnitTrustNav)),
                     grid.Column(header: "Nav Date", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.UnitTrustNavDate)),

                      grid.Column(header: "BID Price / Unit", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.UnitTrustBidPrice)),
                     grid.Column(header: "BID Price Date", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.UnitTrustBidPriceDate)),

                     grid.Column(header: "Purchase (THB)", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.UnitTrustPurchaseValueNet)),
                     grid.Column(header: "BID Price Amount", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.UnitTrustBidPriceAmt))


                    );

            }

            if (type == InstrumentType.Equity)
            {
                return grid.Columns(

                   grid.Column(header: "ลบ", canSort: false, format: (item) => helper.Raw("<input type=\"image\" id=\"BtnDelete\"  name=\"BtnDelete\"  onclick=\"return del('" + item.Key + "')\"  value=\"" + item.Key + "\" src=\"" + url.Content("~/Content/images/delete.png") + "\"  title=\"ลบ\">")),
                     grid.Column(header: "NO.", format: item => (item.WebGrid.Rows.IndexOf(item) + 1) + (grid.PageIndex * grid.RowsPerPage), canSort: false),

                     grid.Column(columnName: "EquityTransactionType", header: "Trans", canSort: false),

                     grid.Column(columnName: "EquityCounterPartyName", header: "Counter party", canSort: false),

                     grid.Column(header: "Time to Maturity", format: (item) => ThaireInvestmentWeb.Util.WebUtil.NonApplicableIfZero(item.EquityTimeToMaturity)),
                     grid.Column(header: "Trade Date", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.EquityTradeDate)),
                     grid.Column(header: "Settlement Date", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.EquitySettlementDate)),
                     grid.Column(header: "Transaction Unit", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatInt(item.EquityUnit)),
                     grid.Column(header: "Remain Unit", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatInt(item.EquityRemainUnit)),

                     grid.Column(header: "Par", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.EquityPar)),
                     grid.Column(header: "Nav", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.EquityNav)),
                     grid.Column(header: "Nav Date", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.EquityNavDate)),

                      grid.Column(header: "BID Price / Unit", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.EquityBidPrice)),
                     grid.Column(header: "BID Price Date", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.EquityBidPriceDate)),

                     grid.Column(header: "Purchase (THB)", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.EquityPurchaseValueNet)),
                     grid.Column(header: "BID Price Amount", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.EquityBidPriceAmt))


                    );

            }

            if (type == InstrumentType.DepositAtFinancial)
            {
                return grid.Columns(

                   grid.Column(header: "ลบ", canSort: false, format: (item) => helper.Raw("<input type=\"image\" id=\"BtnDelete\"  name=\"BtnDelete\"  onclick=\"return del('" + item.Key + "')\"  value=\"" + item.Key + "\" src=\"" + url.Content("~/Content/images/delete.png") + "\"  title=\"ลบ\">")),
                     grid.Column(header: "NO.", format: item => (item.WebGrid.Rows.IndexOf(item) + 1) + (grid.PageIndex * grid.RowsPerPage), canSort: false),
                                      grid.Column(columnName: "DepositTransactionType", header: "Trans.", canSort: false),
                     grid.Column(columnName: "DepositVoucherNo", header: "A/C No. , Voucher No.", canSort: false),
                      grid.Column(columnName: "DepositBankName", header: "Bank Name", canSort: false),
                       grid.Column(columnName: "DepositBankBranchName", header: "Branch", canSort: false),
                     grid.Column(header: "TTM.", format: (item) => ThaireInvestmentWeb.Util.WebUtil.NonApplicableIfZero(item.DepositTtm)),
                     grid.Column(header: "Settle Date", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.DepositSettlementDate)),
                      grid.Column(columnName: "DepositTerm", header: "TERM", canSort: false),
                     grid.Column(header: "AMOUNT", style: "columnNumber", format: (item) => ThaireInvestmentWeb.Util.WebUtil.FormatDecimal5Digit(item.DepositAmount))


                    );

            }
            return null;
        }
    }
}